
package com.yyfax.ph.personal.settings;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

public class SettingModel extends Model {
	private static final String TAG = SettingModel.class.getSimpleName();
	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		LogoutResult logoutResult = cast(obj);
		EventAgent.post(logoutResult);
	}

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.exitLogin(token, new Logout());
	}

	public interface Service {
		@POST("sys/user/logout")
		Observable<LogoutResult> exitLogin(@Header("token") String token, @Body Logout params);
	}

	public static class Logout {
		String regId = YJPH.getInstance().getPreferenceManager().getJPushRegId();
	}

	public static class LogoutResult extends BaseResultEntity {

	}

}
